package com.adtech.farmProducts.activities.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.adtech.common.Common;
import com.adtech.common.http.AsyncHttpPostFormData;
import com.adtech.common.http.AsyncHttpResponse;
import com.adtech.common.http.AsyncOkHttpClient;
import com.adtech.common.http.AsyncResponseHandler;
import com.adtech.common.model.RspModel;
import com.adtech.common.utils.AccountManagers;
import com.adtech.common.widgets.load.core.LoadManager;
import com.adtech.common.widgets.recycler.RecyclerViewAdapter;
import com.adtech.farmProducts.App;
import com.adtech.farmProducts.R;
import com.adtech.farmProducts.adapter.SourceInfoAdapter;
import com.adtech.farmProducts.base.BaseActivity;
import com.adtech.farmProducts.base.BaseNfcActivity;
import com.adtech.farmProducts.model.OrderInfo;
import com.adtech.farmProducts.model.SourceInfo;
import com.adtech.farmProducts.widget.EmptyView;
import com.adtech.farmProducts.widget.ErrorView;
import com.google.gson.reflect.TypeToken;
import com.gyf.barlibrary.ImmersionBar;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Time:2020/6/20
 * Created by xiaocz
 * Describe 消费者-溯源详情
 */
public class CSourceInfoActivity extends BaseNfcActivity {

    @BindView(R.id.tv_title)
    TextView tv_title;
    @BindView(R.id.tv_name)
    TextView tv_name;
    @BindView(R.id.tv_code)
    TextView tv_code;
    @BindView(R.id.recycler_view)
    public RecyclerView mRecyclerView;
    /**
     * DATA
     */
    private SourceInfoAdapter orderListAdapter;
    private ArrayList<SourceInfo> list;

    public static void show(Context context, ArrayList<SourceInfo> list) {
        Intent intent = new Intent(context, CSourceInfoActivity.class);
        intent.putParcelableArrayListExtra("list", list);
        context.startActivity(intent);
    }

    @Override
    protected boolean initArgs(Bundle bundle) {
        if (bundle != null) {
            list = bundle.getParcelableArrayList("list");
        }
        return super.initArgs(bundle);
    }

    @Override
    protected int getLayoutSourceId() {
        return R.layout.activity_c_source_info;
    }

    @Override
    protected void initData() {
        super.initData();
        tv_title.setText("溯源详情");
        mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        orderListAdapter = new SourceInfoAdapter(new RecyclerViewAdapter.AdapterListenerImpl<SourceInfo>() {
            @Override
            public void onItemClick(RecyclerViewAdapter.ViewHolder<SourceInfo> holder, SourceInfo data) {
                super.onItemClick(holder, data);
            }
        });
        mRecyclerView.setAdapter(orderListAdapter);
        if(list!=null){
            orderListAdapter.replace(list);
            tv_name.setText(list.get(0).getProductName());
            tv_code.setText(list.get(0).getSourceCode());
        }
    }
}
